package com.arun.mappers;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.springframework.context.annotation.Configuration;

import com.arun.entity.C7MTP;


@Configuration
@Mapper
public interface C7MTPMapper {
	  //注意这里只有一个参数，则#{}中的标识符可以任意取
    @Select("select * from CUX_C7MTP_INFO where unqueid=#{unqueid}")
    public C7MTP retrieveC7MTPByUid(@Param("unqueid")String unqueid);
    
    @Select("select * from CUX_C7MTP_INFO")
    public List<C7MTP> retrieveAll();
    
    //@Select("SELECT SEQ_CUX_MASK_INFO.CURRVAL AS ID from DUAL")
    // MyBatis 插入空值时，需要指定JdbcType

    @Insert("INSERT INTO CUX_C7MTP_INFO(sn,mac,is_upload,code,version,error) "
            + "VALUES(#{sn,jdbcType=VARCHAR},#{mac,jdbcType=VARCHAR},#{is_upload,jdbcType=VARCHAR},"
            + "#{code,jdbcType=VARCHAR},#{version},#{error,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    // mybatis oracle 新增时将主键值返回
    //@SelectKey(statement="select SEQ_CUX_MEDIA_INTERFACE_LOG.CURRVAL from dual", keyProperty="id", before=false, resultType=Long.class)
    public int addNewC7MTP(C7MTP c7mtp);
                                                                                                                                                                                                                                   
    @Delete("delete from cux_media_interface_log where id=#{id}")
    public void deleteInterfaceToLog(int id);
    
    // mybatis实现数据库乐观锁解决并发问题实践
    @Update("update CUX_C7MTP_INFO set ipAddress=#{ipAddress},queryDate=#{queryDate},queryCount=#{queryCount}"
            + " where id=#{id}")
    public void updateC7MTP(C7MTP c7mtp);	
    
    /**
     *  获取 serialnum
     */
    @Select("SELECT SEQ_CUX_serialnum.NEXTVAL AS serialnum from DUAL")
    //@Select("select upper(rawtohex(sys_guid())) serialnum  from dual")
    public Map<String,Object> getSerialNum();
}
